package com.fly.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fly.common.R;
import com.fly.mapper.BlogMapper;
import com.fly.pojo.*;
import com.fly.service.BlogService;

import com.fly.service.TagUserService;
import com.fly.service.TypeService;
import jdk.nashorn.internal.objects.AccessorPropertyDescriptor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Service;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.*;


@Service
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {
    @Autowired
    private TagUserService tagUserService;
    @Override
    public R<String> saveBlog(Blogpojo blogpojo,long id) {
        TagAndUerID tagAndUerID=new TagAndUerID();

        Blog blog =new Blog();
        blog.setUserId(id) ;
        BeanUtils.copyProperties(blogpojo,blog,"tag");
        blog.setViews(0);
        blog.setCreateTime(new Date());
        blog.setUpdateTime(new Date());
        this.save(blog);
        tagAndUerID.setBlogsId(blog.getId());
        Long idd= blogpojo.getTagId();
        tagAndUerID.setTagsId(idd);

        tagUserService.save(tagAndUerID);

        return null;
    }

    @Override
    public R<String> updaBlog(Blogpojo blogpojo, long id) {
        TagAndUerID tagAndUerID=new TagAndUerID();
        Blog blog =new Blog();
        blog.setUserId(id) ;
        BeanUtils.copyProperties(blogpojo,blog,"tag");

        blog.setUpdateTime(new Date());
        this.updateById(blog);
        tagAndUerID.setBlogsId(blog.getId());
        Long idd= blogpojo.getTagId();
        tagAndUerID.setTagsId(idd);

        tagUserService.updateById(tagAndUerID);
//        System.out.println(blog);
        return null;

    }
}
